<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="../../../common/common-easyui.jspf" %>
<!DOCTYPE html >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>试卷维护</title>
</head>
<body>
<table id="dg" title="试卷维护" class="easyui-datagrid" style="width:100%;height:100%"
       data-options="
			url:'paperInfoController?flag=query',
			toolbar:'#toolbar',
			rownumbers:'true',
			 fitColumns:'true' ,
			 singleSelect:'true'">
    <thead>
    <tr>
        <th data-options="field:'paperId'" width="50">试卷编号</th>
        <th data-options="field:'paperName'" width="50">试卷名称</th>
        <th data-options="field:'courseId'" width="50">科目编号</th>
        <th data-options="field:'examTime'" width="50">考试时长</th>
        <th data-options="field:'teaId'" width="50">老师编号</th>
        <th width="50" data-options="
					field:'paperDate',
				    formatter:function(value) {
						return getTimer(value);
					 }
				">出题时间
        </th>
        <th data-options="field:'passScore'" width="50">通过分数</th>
        <th data-options="field:'ruleId'" width="50">组卷规则编号</th>
        <th width="50" data-options="
					field:'testId',
				    formatter:function(value) {
				    	if(value==1){
				    		return '手动组卷';
				    	}else{				    	
							return '随机组卷';
				    	}
					 }
				">组卷规则
        </th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-add', plain:'true'" onclick="newPaper()">添加试卷</a>
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-edit', plain:'true'"
       onclick="editPaper()">编辑试卷</a>
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-remove', plain:'true'" onclick="destroyPaper()">移除试卷</a>
</div>
<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
     data-options="closed:'true', buttons:'#dlg-buttons'">
    <div class="ftitle">试卷信息</div>
    <form id="fm" method="post">
        <div class="fitem">
            <label>试卷名称:</label>
            <input name="paperName">
        </div>
        <div class="fitem">
            <label>科目编号:</label>
            <input name="courseId">
        </div>
        <div class="fitem">
            <label>考试时长:</label>
            <input name="examTime">
        </div>
        <div class="fitem">
            <label>教师编号:</label>
            <input name="teaId">
        </div>
        <div class="fitem">
            <label>出题时间:</label>
            <input type="datetime-local" name="paperDate">
        </div>
        <div class="fitem">
            <label>及格分数:</label>
            <input name="passScore">
        </div>
        <div class="fitem">
            <label>试卷规则编号:</label>
            <input name="ruleId">
        </div>
        <div class="fitem">
            <label>组卷类型(1.手动,2.自动):</label>
            <input name="testId">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-ok'" onclick="savePaper()">Save</a>
    <a href="#" class="easyui-linkbutton" data-options=" iconCls:'icon-cancel'"
       onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
</div>
<script type="text/javascript">
    //添加函数
    function newPaper() {
        $('#dlg').dialog('open').dialog('setTitle', '添加组卷规则');
        $('#fm').form('clear');
        url = 'paperInfoController?flag=add';
    }
    //修改函数
    function editPaper() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('setTitle', '修改组卷规则');
            $('#fm').form('load', row);
            url = 'paperInfoController?flag=update&paperId=' + row.paperId;
        }
    }
    //保存函数
    function savePaper() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {

                if (data == "ok") {
                    $('#dlg').dialog('close');		// 清除数据
                    $('#dg').datagrid('reload');	// 重新加载数据
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                }
            }
        });
    }
    //删除函数
    function destroyPaper() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', '确定删除吗?', function (r) {
                if (r) {
                    $.get('paperInfoController', {flag: "dele", paperId: row.paperId}, function (data) {
                        if (data == "ok") {
                            $('#dg').datagrid('reload');	// 重新加载数据
                        } else {
                            $.messager.show({	//错误提示
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    });
                }
            });
        }
    }
    // 时间处理
    function getTimer(value) {
        // 创建一个日期对象
        // new 把该对象放到内存空间中存储起来
        var date = new Date(value);
        // 获取年份
        var year = date.getFullYear();
        // 获取月份
        var month = date.getMonth() + 1;
        // 获取天数
        var day = date.getDate();

        // 获取小时
        var hours = handler(date.getHours());
        // 获取分钟数
        var minutes = handler(date.getMinutes());
        // 获取秒数
        var seconds = handler(date.getSeconds());

        var currentTime = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;

        return currentTime;
    }

    /*定义处理如果时间小于10前面加0的函数*/
    function handler(time) {

        if (time < 10) {
            time = "0" + time;
        }

        // 返回当前格式化后的字符串
        return time;

    }
</script>
</body>
</html>